package concurrecy;

import java.util.concurrent.TimeUnit;

class DaemonThread extends Thread {

    private int count = 0;

    public DaemonThread() {
        setDaemon(true);
        start();
    }

    @Override
    public String toString() {
        return super.toString() + ": " + count ++ ;
    }

    @Override
    public void run() {
        while(true) {
            System.out.println(this);
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class DaemonDemo {
    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 5; i++) {
            new DaemonThread();
        }
        TimeUnit.SECONDS.sleep(5);
    }
}
